package com.ice.framework.views

import android.content.Context
import android.util.AttributeSet
import androidx.viewpager.widget.ViewPager

class WrapContentHeightViewPager : ViewPager {

    constructor(context: Context):super(context)

    constructor(context: Context,attributeSet: AttributeSet):super(context,attributeSet)

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        var height=0
        for (i in 0 until childCount){
            val child=getChildAt(i)
            child.measure(widthMeasureSpec,MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED))
            val h=child.measuredHeight
            if(h>height){
                height=h
            }
        }
        val heightMeasureSpec1=MeasureSpec.makeMeasureSpec(height,MeasureSpec.EXACTLY)
        super.onMeasure(widthMeasureSpec, heightMeasureSpec1)
    }
}